<?php

/**
 * Class ApiController
 */
class InformationController extends BaseController
{

	/*
	|--------------------------------------------------------------------------
	| API控制器
	|--------------------------------------------------------------------------
	|   ShowInformationList             资讯列表
	|
	*/

    /**
     * 资讯列表
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowInformationList()
    {
        $info = InformationService::instance()->ShowInformationList();
        return $this->view('admin.show_information')->with('information',$info);
    }

    /**
     * 新增资讯
     * @author alice
     * @date 2016-1-19
     * @return mixed
     * @throws Exception
     */
    public function AddInformation()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->title                    =     $this->getParam('title');
            $aData->author                   =     $this->getParam('author');
            $aData->source                   =     $this->getParam('source');
            $aData->cate_id                  =     $this->getParam('cate_id');
            $aData->keywords                 =     $this->getParam('keywords');
            $aData->introduces               =     $this->getParam('introduces');
            $aData->content                  =     $this->getParam('content');
            $aData->img                      =     $this->getParam('img');

            #逻辑操作
            InformationService::instance()->AddInformation($aData);
            return Redirect::to('/show_information');}else{
            return $this->view('admin.add_information')->with('types',InformationEnum::$information_types);
        }
    }

    /**
     * 修改资讯
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function EditInformation()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->title                    =     $this->getParam('title');
            $aData->zx_id                    =     $this->getParam('zx_id');
            $aData->author                   =     $this->getParam('author');
            $aData->source                   =     $this->getParam('source');
            $aData->cate_id                  =     $this->getParam('cate_id');
            $aData->keywords                 =     $this->getParam('keywords');
            $aData->introduces               =     $this->getParam('introduces');
            $aData->content                  =     $this->getParam('content');
            $aData->img                      =     $this->getParam('img');

            #逻辑操作
            InformationService::instance()->EditInformation($aData);
            return Redirect::to('/show_information');}else{
            $id = $this->getParam('zx_id');
            $info = InformationService::instance()->ShowInformationInfo($id);
            return $this->view('admin.edit_information')->with(['information'=>$info, 'types'=>InformationEnum::$information_types]);
        }
    }

}
